package com.share.redisson.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.spring.data.connection.RedissonConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @desc:
 * @author:caifan
 * @date:2020/4/19
 */
@Configuration
@PropertySource("classpath:redis.properties")
public class RedisConfig {

    @Bean
    public RedissonClient redissonClient(@Value("${spring.redis.host}")String host,
                                         @Value("${spring.redis.port}")Integer port,
                                         @Value("${spring.redis.password}")String password) {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + host + ":" + port).setPassword(password);//单节点配置

        //config.useClusterServers();//集群配置
        //config.useMasterSlaveServers();//主从配置
        //config.useSentinelServers();//使用哨兵模式
        return Redisson.create(config);

    }

}
